/*
 * @Author: szx
 * @Date: 2022-03-19 13:30:42
 * @LastEditTime: 2022-03-19 13:41:36
 * @Description:
 * @FilePath: \leetcode\700-799\763\763.js
 */
/**
 * @param {string} s
 * @return {number[]}
 */
var partitionLabels = function (s) {
    const arr = new Array(26).fill(0);
    for (let i = 0; i < s.length; i++) {
        arr[s.charCodeAt(i) - 97] = i;
    }
    let left = 0,
        right = 0;
    const res = [];
    for (let i = 0; i < s.length; i++) {
        right = Math.max(right, arr[s.charCodeAt(i) - 97]);
        if (right == i) {
            res.push(right - left + 1);
            left = right + 1;
        }
    }
    return res;
};
console.log(partitionLabels('ababcbacadefegdehijhklij'));
